package com.zyark.web.controller;

import com.zyark.model.ImageModel;
import com.zyark.web.util.FasfdfsClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by ron on 17-3-30.
 */
@RequestMapping("/test")
@Controller
public class TestController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(TestController.class);

//    @Resource
//    FasfdfsClientUtil fasfdfsClientUtil;

    @RequestMapping("/t1")
    public String test1(Model model){
        model.addAttribute("hello", "你好");
        return "test";
    }

    @RequestMapping(value = "/upload",method = RequestMethod.POST)
    public void uploadFile(@ModelAttribute ImageModel imageModel, HttpServletResponse response){
        MultipartFile[] multipartFiles = imageModel.getImages();
        for (MultipartFile multipartFile : multipartFiles){
            try {
//                String filePath = fasfdfsClientUtil.uploadMutipartFile(multipartFile);
//                logger.info(filePath);
//                super.writeJson(filePath,response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
